<template>
  <div>
    <!-- <a-button type="primary" @click="showModal"> Open Modal with async logic </a-button> -->
    <a-modal title="发送" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
      <a-form-model
        :label-col="{ span: 5 }"
        :wrapper-col="{ span: 12 }"
        :model="form"
        :rules="rules"
        @submit="handleSubmit"
        @submit.native.prevent
      >
        <a-form-model-item label="连接名称">
          <a-select v-model="form.channelCode" prop="channelId" show-search optionFilterProp="children">
            <a-select-option :value="item.channelCode" :key="index" v-for="(item, index) in channelList">
              {{ item.channelName }}
            </a-select-option>
          </a-select>
        </a-form-model-item>

        <!-- <a-form-model-item>
          <a-button type="primary" html-type="submit"> 发送 </a-button>
        </a-form-model-item> -->
      </a-form-model>
    </a-modal>
  </div>
</template>
<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  data() {
    return {
      ModalText: 'Content of the modal',
      visible: false,
      confirmLoading: false,
      rules: {
        channelId: [{ required: true, message: '请选择连接名称', trigger: 'blur' }],
      },

      form: {},
      channelList: [],
      url: {
        channelList: '/channel/nmcChannelInfo/list',
        send: '/channel/nmcChannelInfo/send',
      },
    }
  },
  methods: {
    handleSubmit(e) {
      console.log(this.form)
      getAction(this.url.send, this.form)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
          } else {
            this.$message.error(res.message)
          }
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    showModal(record) {
      console.log(record)
      this.visible = true
      this.form.packageCode = record.packageCode
      getAction(this.url.channelList, { pageSize: -1 }).then((res) => {
        if (res.success) {
          console.log(res)
          this.channelList = res.result.records
        }
      })
      // this.channelList=res.re
    },
    handleOk(e) {
      this.confirmLoading = true
      // setTimeout(() => {
      //   this.confirmLoading = false
      // }, 2000)
      getAction(this.url.send, this.form).then((res) => {
        if (res.success) {
          this.visible = false
          this.confirmLoading = false
          this.$notification.success({
            message: '操作成功',
            description: `${res.message}`,
          })
          this.form = {}
        } else {
          this.visible = false
          this.confirmLoading = false
          this.$notification.error({
            message: '操作失败',
            description: `${res.message}`,
          })
          this.form = {}
        }
      })
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
    },
  },
}
</script>
